home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PsL Monthly 1993 December
/
PSL Monthly Shareware CD-ROM (December 1993).iso
/
prgmming
/
dos
/
c
/
cwscr.exe
/
MYSCRLL.CPP
< prev
next >
Wrap
Text File
|
1991-07-28
|
3KB
|
118 lines
/*
Scrolling file window module class specification.
This is the source file that contains the actual source to the
routines used to display a file in a window and scroll through
the file a page at a time.
Library : mycpp.lib
*/
static char MyScrll_Id[] = "myscrll.cpp 1.00 04/04/91";
/*
Version notes :
1.0 - Original creation / release.
*/
#include "myscrll.h"
/* ------------------------------------------------------------------ */
void
myScroll::wait(){
int done = FALSE;
while( !done ){
if( kbhit()){
done = TRUE;
if( !getch()) getch();
}
if( aMouse.pressed( LEFT_BUTTON ))
done = TRUE;
}
}
/* .................................................................. */
int
myScroll::next_page(){
int c, cnt = 0, line = 0;
int done = FALSE, eof = FALSE;
char str[80], *pstr = str;
scroll_screen->clear( x, y, w, h, SCR_F_White | SCR_B_Black );
while( !done ){
if(( c = getc( fp )) == EOF ){
done = eof = TRUE;
} else {
if( c == '\n' ){
if( cnt > w )
str[w] = '\0';
else
str[cnt] = '\0';
scroll_screen->print( x, line + y, str );
cnt = 0;
pstr = str;
line++;
if( line > ( h - 1 ))
done = TRUE;
} else {
if( cnt < w )
*pstr++ = c;
cnt++;
}
}
}
if(( !done ) && ( cnt > 0 )){
if( cnt > w )
str[w] = '\0';
else
str[cnt] = '\0';
scroll_screen->print( x, line + y, str );
}
return( eof );
}
/* .................................................................. */
void
myScroll::display( char *filename ){
if(( fp = fopen( filename, "r" )) != NULL ){
const save_type *old_screen = scroll_screen->save( 0, 0, 80, 25 );
scroll_screen->cursor_hide();
int done = FALSE;
while( !done ){
done = next_page();
wait();
}
scroll_screen->restore( old_screen );
scroll_screen->cursor_show();
fclose( fp );
}
}
/* ================================================================== */
#define debug_scroll
#ifdef debug_scroll
main( int argc, char *argv[] ){
myScroll aScrollWin( 1, 5, 60, 15 );
if( argc == 2 ){
aScrollWin.display( argv[1] );
}
return 0;
}
#endif